package com.stlm2.controller;

import com.stlm2.dems.service.MessagesService;

import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by apple on 2017/6/13.
 */

@Controller
@RequestMapping("/messagesC")
public class MessagesController {
    @Resource
    private MessagesService messagesService;


    /**
     * 获取用户消息 列表
     * 樊飞龙
     * @param token
     * @param pageNo
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/getUserMessages.json",produces="application/json;charset=UTF-8")
    public  String getUserMessages(String companyCode,String token, String pageNo){
        String date="";
        try {
            date=messagesService.getUserMessages(pageNo,token);
        }catch (Exception e){
            e.printStackTrace();
           return CodeContent.getModelByCode(0,"获取消息失败",null);
        }
        return  date;
    }

    /**
     * 获取单个消息
     *  ffl
     * @param token
     * @param messageId
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/getOneMessages.json",produces="application/json;charset=UTF-8")
    public  String getOneMessages(String companyCode,String token, String messageId){
        String date="";
        try {
            date=messagesService.getOneMessages(token, messageId);
        }catch (Exception e){
            e.printStackTrace();
            return CodeContent.getModelByCode(0,"获取消息失败",null);
        }
        return  date;
    }

    /**
     *获取用户未读消息个数
     * @param token
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/countNotReadMessages.json",produces="application/json;charset=UTF-8")
    public  String countNotReadMessages(String companyCode,String token){
        String date="";
        try {
            date=messagesService.countNotReadMessages(token);
        }catch (Exception e){
            e.printStackTrace();
            return CodeContent.getModelByCode(0,"获取消息个数失败",null);
        }
        return  date;
    }

    /*
    修改消息为已读
    ffl
     */
    @ResponseBody
    @RequestMapping(value="/updateNotReadMessages.json",produces="application/json;charset=UTF-8")
    public  String updateNotReadMessages(String companyCode,String token, String messageId){
        String date="";
        try {
            date=messagesService.updateNotReadMessages(token, messageId);
        }catch (Exception e){
            e.printStackTrace();
            return CodeContent.getModelByCode(0,"获取消息个数失败",null);
        }
        return  date;
    }


    /**
     * ffl
     * 2017-08-25 15:01:25
     * 将用户领取的红包 保存在redis 中12小时
     * @param token
     * @param integral
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/saveUserIntegralRedis.json",produces="application/json;charset=UTF-8")
    public String saveUserIntegralRedis(String companyCode,String token,String integral){
       // return userIntegralService.saveUserIntegral(token,integral);
        return null;
    }

//    /**
//     * ffl
//     * 2017-08-25 15:54:19
//     * 将店铺做单 保存在redis 中24小时
//     * @param token
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping(value="/saveShopOrderRedis.json",produces="application/json;charset=UTF-8")
//    public String saveShopOrderRedis(String token){
//        return shopService.saveShopOrderRedis(token);
//    }

    /**ffl
     * 2017-08-25 18:10:59
     * 商城首页 滚动 消息
     * @param token
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/showRedisMessage.json",produces="application/json;charset=UTF-8")
    public String showRedisMessage(String companyCode,String token){
        return messagesService.rollMessage(token);
    }


}
